/**
 * 数据处理
 * @param {Array} datas
 * @param {Number} option.day: 数据区间
 * @param {String} option.type: 数据类型
 * @return {Array} 返回两个数据列
 */
export default function(datas, option) {
  let { day, type } = option;
  let sh300 = []; // 沪深300
  // 融券-偿还量
  let rqchl = []; // 1
  let rqchl_threed = []; // 3
  let rqchl_fived = []; // 5
  let rqchl_tend = []; // 10
  // 融券-净卖出(股)
  let rqjmg = [];
  let rqjmg_threed = [];
  let rqjmg_fived = [];
  let rqjmg_tend = [];
  // 融券-卖出量
  let rqmcl = [];
  let rqmcl_threed = [];
  let rqmcl_fived = [];
  let rqmcl_tend = [];
  let rqye = []; // 融券余额
  let rqyl = []; // 融券余量
  // 融资-偿还量
  let rzche = [];
  let rzche_threed = [];
  let rzche_fived = [];
  let rzche_tend = [];
  // 融资-净买入
  let rzjme = [];
  let rzjme_threed = [];
  let rzjme_fived = [];
  let rzjme_tend = [];
  // 融资--买入额
  let rzmre = [];
  let rzmre_fived = [];
  let rzmre_tend = [];
  let rzmre_threed = [];
  let rzrqye = []; // 融资融券当日余额
  let rzrqyecz = []; // 融资融券余额差值
  let rzye = []; // 融资--当日余额
  let rzyezb = []; // 融资-当日余额占流通市值比
  // 涨跌幅
  let zdf_threed = [];
  let zdf_fived = [];
  let zdf_tend = [];

  datas.forEach((item, i) => {
    sh300.push({ y: item.close_price, x: i, time: item.dim_date });
    rqchl.push({ y: item.rqchl, x: i, time: item.dim_date });
    rqchl_fived.push({ y: item.rqchl_fived, x: i, time: item.dim_date });
    rqchl_tend.push({ y: item.rqchl_tend, x: i, time: item.dim_date });
    rqchl_threed.push({ y: item.rqchl_threed, x: i, time: item.dim_date });
    rqjmg.push({ y: item.rqjmg, x: i, time: item.dim_date });
    rqjmg_fived.push({ y: item.rqjmg_fived, x: i, time: item.dim_date });
    rqjmg_tend.push({ y: item.rqjmg_tend, x: i, time: item.dim_date });
    rqjmg_threed.push({ y: item.rqjmg_threed, x: i, time: item.dim_date });
    rqmcl.push({ y: item.rqmcl, x: i, time: item.dim_date });
    rqmcl_fived.push({ y: item.rqmcl_fived, x: i, time: item.dim_date });
    rqmcl_tend.push({ y: item.rqmcl_tend, x: i, time: item.dim_date });
    rqmcl_threed.push({ y: item.rqmcl_threed, x: i, time: item.dim_date });
    rqye.push({ y: item.rqye, x: i, time: item.dim_date });
    rqyl.push({ y: item.rqyl, x: i, time: item.dim_date });
    rzche.push({ y: item.rzche, x: i, time: item.dim_date });
    rzche_fived.push({ y: item.rzche_fived, x: i, time: item.dim_date });
    rzche_tend.push({ y: item.rzche_tend, x: i, time: item.dim_date });
    rzche_threed.push({ y: item.rzche_threed, x: i, time: item.dim_date });
    rzjme.push({ y: item.rzjme, x: i, time: item.dim_date });
    rzjme_fived.push({ y: item.rzjme_fived, x: i, time: item.dim_date });
    rzjme_tend.push({ y: item.rzjme_tend, x: i, time: item.dim_date });
    rzjme_threed.push({ y: item.rzjme_threed, x: i, time: item.dim_date });
    rzmre.push({ y: item.rzmre, x: i, time: item.dim_date });
    rzmre_fived.push({ y: item.rzmre_fived, x: i, time: item.dim_date });
    rzmre_tend.push({ y: item.rzmre_tend, x: i, time: item.dim_date });
    rzmre_threed.push({ y: item.rzmre_threed, x: i, time: item.dim_date });
    rzrqye.push({ y: item.rzrqye, x: i, time: item.dim_date });
    rzrqyecz.push({ y: item.rzrqyecz, x: i, time: item.dim_date });
    rzye.push({ y: item.rzye, x: i, time: item.dim_date });
    rzyezb.push({ y: item.rzyezb, x: i, time: item.dim_date });
    zdf_fived.push({ y: item.zdf_fived, x: i, time: item.dim_date });
    zdf_tend.push({ y: item.zdf_tend, x: i, time: item.dim_date });
    zdf_threed.push({ y: item.zdf_threed, x: i, time: item.dim_date });
  });

  // 沪深300涨跌幅添加颜色
  // 大于0是红色, 小于0是绿色
  const addColor = (item) => {
    item.color = item.y > 0 ? "#FD4848" : "#08751c";
    return item;
  };
  zdf_threed = zdf_threed.map(addColor);
  zdf_fived = zdf_fived.map(addColor);
  zdf_tend = zdf_tend.map(addColor);

  let dataTable = {
    "1-rzrqye": [
      {
        data: sh300,
        type: "spline",
        name: "@收盘-沪深300",
        color: "#EA2827",
      },
      {
        data: rzrqye,
        type: "spline",
        name: "融资融券余额(元)",
        yAxis: 1,
        color: "#5AD119",
      },
    ],
    "1-rzye": [
      {
        data: sh300,
        type: "spline",
        name: "@收盘-沪深300",
        color: "#EA2827",
      },
      {
        data: rzye,
        type: "spline",
        name: "融资余额(元)",
        yAxis: 1,
        color: "#22AB37",
      },
    ],
    "1-rzjme": [
      {
        data: sh300,
        type: "spline",
        name: "@收盘-沪深300(%)",
        color: "#EA2827",
      },
      {
        data: rzjme,
        type: "column",
        name: "融资净买入(股)",
        yAxis: 1,
        color: "#7D68F2",
      },
    ],
    "1-rzyezb": [
      {
        data: sh300,
        type: "spline",
        name: "@收盘-沪深300",
        color: "#EA2827",
      },
      {
        data: rzyezb,
        type: "spline",
        name: "融资余额占流通市值比(%)",
        yAxis: 1,
        color: "#BE37FF",
      },
    ],
    "1-rzrqyecz": [
      {
        data: sh300,
        type: "spline",
        name: "@收盘-沪深300",
        color: "#EA2827",
      },
      {
        data: rzrqyecz,
        type: "spline",
        name: "融资融券余额差值(元)",
        yAxis: 1,
        color: "#004986",
      },
    ],
    "1-rqye": [
      {
        data: sh300,
        type: "spline",
        name: "@收盘-沪深300",
        color: "#EA2827",
      },
      {
        data: rqye,
        type: "spline",
        name: "融券余额(元)",
        yAxis: 1,
        color: "#FF8A00",
      },
    ],
    "1-rqmcl": [
      {
        data: sh300,
        type: "spline",
        name: "@收盘-沪深300",
        color: "#EA2827",
      },
      {
        data: rqmcl,
        type: "column",
        name: "融券净卖出(股)",
        yAxis: 1,
        color: "#008FCE",
      },
    ],
    // ====== 3日 ========
    "3-rqjmg_threed": [
      {
        data: zdf_threed,
        type: "column",
        name: "@3日涨跌幅(%)-沪深300",
      },
      {
        data: rqjmg_threed,
        type: "column",
        name: "3日融券净卖出(股)",
        yAxis: 1,
        color: "#5AD119",
      },
    ],
    "3-sh300": [
      {
        data: zdf_threed,
        type: "column",
        name: "@3日涨跌幅(%)-沪深300",
      },
      {
        data: sh300,
        type: "spline",
        name: "收盘-沪深300(%)",
        yAxis: 1,
        color: "#BE37FF",
      },
    ],
    "3-rzmre_threed": [
      {
        data: zdf_threed,
        type: "column",
        name: "@3日涨跌幅(%)-沪深300",
      },
      {
        data: rzmre_threed,
        type: "column",
        name: "3日融资买入额(元)",
        yAxis: 1,
        color: "#22AB37",
      },
    ],
    "3-rzche_threed": [
      {
        data: zdf_threed,
        type: "column",
        name: "@3日涨跌幅(%)-沪深300",
      },
      {
        data: rzche_threed,
        type: "column",
        name: "3日融资偿还额(元)",
        yAxis: 1,
        color: "#BE37FF",
      },
    ],
    "3-rzjme_threed": [
      {
        data: zdf_threed,
        type: "column",
        name: "@3日涨跌幅(%)-沪深300",
      },
      {
        data: rzjme_threed,
        type: "column",
        name: "3日融资净买入(元)",
        yAxis: 1,
        color: "#004986",
      },
    ],
    "3-rqmcl_threed": [
      {
        data: zdf_threed,
        type: "column",
        name: "@3日涨跌幅(%)-沪深300",
      },
      {
        data: rqmcl_threed,
        type: "column",
        name: "3日融券卖出量(股)",
        yAxis: 1,
        color: "#FF8A00",
      },
    ],
    "3-rqchl_threed": [
      {
        data: zdf_threed,
        type: "column",
        name: "@3日涨跌幅(%)-沪深300",
      },
      {
        data: rqchl_threed,
        type: "column",
        name: "3日融券偿还量(股)",
        yAxis: 1,
        color: "#008FCE",
      },
    ],
    "5-rqjmg_fived": [
      {
        data: zdf_fived,
        type: "column",
        name: "@5日涨跌幅(%)-沪深300",
      },
      {
        data: rqjmg_fived,
        type: "column",
        name: "5日融券净卖出(股)",
        yAxis: 1,
        color: "#5AD119",
      },
    ],
    "5-sh300": [
      {
        data: zdf_fived,
        type: "column",
        name: "@5日涨跌幅(%)-沪深300",
      },
      {
        data: sh300,
        type: "spline",
        name: "收盘-沪深300(%)",
        yAxis: 1,
        color: "#BE37FF",
      },
    ],
    "5-rzmre_fived": [
      {
        data: zdf_fived,
        type: "column",
        name: "@5日涨跌幅(%)-沪深300",
      },
      {
        data: rzmre_fived,
        type: "column",
        name: "5日融资买入额(元)",
        yAxis: 1,
        color: "#22AB37",
      },
    ],
    "5-rzche_fived": [
      {
        data: zdf_fived,
        type: "column",
        name: "@5日涨跌幅(%)-沪深300",
      },
      {
        data: rzche_fived,
        type: "column",
        name: "5日融资偿还额(元)",
        yAxis: 1,
        color: "#BE37FF",
      },
    ],
    "5-rzjme_fived": [
      {
        data: zdf_fived,
        type: "column",
        name: "@5日涨跌幅(%)-沪深300",
      },
      {
        data: rzjme_fived,
        type: "column",
        name: "5日融资净买入(股)",
        yAxis: 1,
        color: "#004986",
      },
    ],
    "5-rqmcl_fived": [
      {
        data: zdf_fived,
        type: "column",
        name: "@5日涨跌幅(%)-沪深300",
      },
      {
        data: rqmcl_fived,
        type: "column",
        name: "5日融券卖出量(股)",
        yAxis: 1,
        color: "#FF8A00",
      },
    ],
    "5-rqchl_fived": [
      {
        data: zdf_fived,
        type: "column",
        name: "@5日涨跌幅(%)-沪深300",
      },
      {
        data: rqchl_fived,
        type: "column",
        name: "5日融券偿还量(股)",
        yAxis: 1,
        color: "#008FCE",
      },
    ],
    "10-rqjmg_tend": [
      {
        data: zdf_tend,
        type: "column",
        name: "@10日涨跌幅(%)-沪深300",
      },
      {
        data: rqjmg_tend,
        type: "column",
        name: "10日融券净卖出(股)",
        yAxis: 1,
        color: "#5AD119",
      },
    ],
    "10-sh300": [
      {
        data: zdf_tend,
        type: "column",
        name: "@10日涨跌幅(%)-沪深300",
      },
      {
        data: sh300,
        type: "spline",
        name: "收盘-沪深300(%)",
        yAxis: 1,
        color: "#BE37FF",
      },
    ],
    "10-rzmre_tend": [
      {
        data: zdf_tend,
        type: "column",
        name: "@10日涨跌幅(%)-沪深300",
      },
      {
        data: rzmre_tend,
        type: "column",
        name: "10日融资买入额(元)",
        yAxis: 1,
        color: "#22AB37",
      },
    ],
    "10-rzche_tend": [
      {
        data: zdf_tend,
        type: "column",
        name: "@10日涨跌幅(%)-沪深300",
      },
      {
        data: rzche_tend,
        type: "column",
        name: "10日融资偿还额(股)",
        yAxis: 1,
        color: "#BE37FF",
      },
    ],
    "10-rzjme_tend": [
      {
        data: zdf_tend,
        type: "column",
        name: "@10日涨跌幅(%)-沪深300",
      },
      {
        data: rzjme_tend,
        type: "column",
        name: "10日融资净买入(股)",
        yAxis: 1,
        color: "#004986",
      },
    ],
    "10-rqmcl_tend": [
      {
        data: zdf_tend,
        type: "column",
        name: "@10日涨跌幅(%)-沪深300",
      },
      {
        data: rqmcl_tend,
        type: "column",
        name: "10日融券卖出量(股)",
        yAxis: 1,
        color: "#FF8A00",
      },
    ],
    "10-rqchl_tend": [
      {
        data: zdf_tend,
        type: "column",
        name: "10日涨跌幅(%)-沪深300",
      },
      {
        data: rqchl_tend,
        type: "column",
        name: "@融券偿还量(股)",
        yAxis: 1,
        color: "#008FCE",
      },
    ],
  };

  let key = `${day}-${type}`;
  console.log("图表数据字段值", key);
  if (!dataTable[key]) {
    throw new Error(`未匹配到数据列:${key}`);
  }

  return dataTable[key];
}
